#ifndef JUDGE_H_
#define JUDGE_H_

# include "stdio.h"
# include "stdlib.h"
# include "string.h"
# include "windows.h"

# include "all_struct.h"

/*
	此部分函数由周珂宇、徐顺杰、栗浩越共同完成
	周：后期整理优化+补充note注释
*/

//判断旅客是否重复预定机票
static int judgeAirplaneRepeat(char* flightNumber,N_guest *current_Guest, Airplane* airplaneHead)
{
	Airplane* p = airplaneHead->next;	while(p)
	{
		if(0 == strcmp(p->flightNumber,flightNumber))
		{
			if(p->personNumber == 0)
				return 0;

			else
			{
				for(int i = 0; i < p->personNumber; i++)
					if (0 == strcmp(p->Guest[i].passcard,current_Guest->passcard))
						return 1;
			}
			
		}

		p = p->next;
	}

	return 0;
}
//判断用户名是否存在
static int judgeUserNameExsit(Guest* guestHead, char userName[20])
{
	Guest* p = guestHead->next;
	while(p)
	{
		if(!strcmp(p->userName,userName))
		{
			return 1;
		}
		p = p->next;
	}
	return 0;
}
//judge用户passcard是否存在
static int judgePascardExsit(Guest* guestHead, char password[30])
{
	Guest* p = guestHead->next;
	while(p)
	{
		if(!strcmp(p->password,password))
		{
			return 1;
		}
		p = p->next;
	}
	return 0;


}
//判断航班是否已经购买过（航班号
static int judgementAirplane(char flightNumber[25],Airplane* airplaneHead)
{
	Airplane* p = airplaneHead->next;
	while(p)
	{
		if(0 == strcmp(p->flightNumber,flightNumber))
		{
			return 1;
		}
		p = p->next;
	}
	return 0;
}
//判断旅客是否登录成功
static Guest* judgeGuestLogin(char userName[20],char password[30],
                              Guest* guestHead,char Guest_UserName[20],N_guest *current_Guest)
{
	Guest* p = guestHead->next;
	while(p)
	{
		if(!strcmp(p->userName,userName) && !strcmp(p->password,password))
		{
			current_Guest = p; //xunzhao 链表对应位次
			return current_Guest;
		}
		p = p->next;
	}
	return NULL;
}


# endif